package co.edu.javeriana.touresbalon.oms.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ada
 */
@Entity
@Table(name = "ADDRESS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Address.findAll", query = "SELECT a FROM Address a"),
    @NamedQuery(name = "Address.findByStreet", query = "SELECT a FROM Address a WHERE a.street = :street"),
    @NamedQuery(name = "Address.findByState", query = "SELECT a FROM Address a WHERE a.state = :state"),
    @NamedQuery(name = "Address.findByZip", query = "SELECT a FROM Address a WHERE a.zip = :zip"),
    @NamedQuery(name = "Address.findByCountry", query = "SELECT a FROM Address a WHERE a.country = :country"),
    @NamedQuery(name = "Address.findByAddresstype", query = "SELECT a FROM Address a WHERE a.addresstype = :addresstype"),
    @NamedQuery(name = "Address.findByAddid", query = "SELECT a FROM Address a WHERE a.addid = :addid"),
    @NamedQuery(name = "Address.findByCity", query = "SELECT a FROM Address a WHERE a.city = :city")})
@SequenceGenerator(name = "IdAddressSequence", sequenceName = "SEQ_ADDRESS")
public class Address implements Serializable {
    private static final long serialVersionUID = 1L;
    @Size(max = 40)
    @Column(name = "STREET")
    private String street;
    @Size(max = 40)
    @Column(name = "STATE")
    private String state;
    @Size(max = 10)
    @Column(name = "ZIP")
    private String zip;
    @Size(max = 40)
    @Column(name = "COUNTRY")
    private String country;
    @Size(max = 10)
    @Column(name = "ADDRESSTYPE")
    private String addresstype;
    @Id
    @GeneratedValue(generator = "IdAddressSequence")
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "ADDID")
    private String addid;
    @Size(max = 40)
    @Column(name = "CITY")
    private String city;
    @JoinTable(name = "CUSTOMER_ADDRESS", joinColumns = {
        @JoinColumn(name = "ADDRESSID", referencedColumnName = "ADDID")}, inverseJoinColumns = {
        @JoinColumn(name = "CUSTID", referencedColumnName = "CUSTID")})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Customer> customerList;

    public Address() {
    }

    public Address(String addid) {
        this.addid = addid;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getAddresstype() {
        return addresstype;
    }

    public void setAddresstype(String addresstype) {
        this.addresstype = addresstype;
    }

    public String getAddid() {
        return addid;
    }

    public void setAddid(String addid) {
        this.addid = addid;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @XmlTransient
    public List<Customer> getCustomerList() {
        return customerList;
    }

    public void setCustomerList(List<Customer> customerList) {
        this.customerList = customerList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (addid != null ? addid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Address)) {
            return false;
        }
        Address other = (Address) object;
        if ((this.addid == null && other.addid != null) || (this.addid != null && !this.addid.equals(other.addid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.edu.javeriana.touresbalon.oms.entities.Address[ addid=" + addid + " ]";
    }
    
}
